Skip to content

feat: oversampled PSF inversion wiring — mapping formalism (phase 2b) - #357

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/psf-oversample-inversion
Jul 8, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/psf-oversample-inversion

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Oversampled PSF convolution, phase 2b (inversion wiring) of the feature designed in #353: pixelized reconstructions via the mapping formalism now convolve at the fine resolution when the dataset's PSF is oversampled. The mapper contributes a new sub-resolution mapping_matrix_over_sampled (one row per sub-pixel, no sub_fraction fold), which the phase-2a Convolver convolves on the fine grid and bins back — convolution now happens before the sub-pixel fold, as the physics requires. mapping.py itself needed no logic change: the PSF application site is the shared AbstractInversionImaging.operated_mapping_matrix_list, exactly as the approved design recorded.

Tracks #356. Builds on #355 (phase 2a).

API Changes

Additive; nothing changes while convolve_over_sample_size == 1.

  • Mapper.mapping_matrix_over_sampled — sub-resolution mapping matrix, shape [total_sub_pixels, source_pixels] in per-pixel sub-block order (the 2a Convolver input format). Binning its rows by the mean of each sub-block reproduces mapping_matrix exactly (tested).
  • AbstractInversionImaging routes every PSF-convolution site (operated_mapping_matrix_list, linear_func_operated_mapping_matrix_dict, mapper_operated_mapping_matrix_dict) through a single helper that picks the sub-resolution matrix for Mapper objects when the PSF is oversampled.
  • Loud guards (InversionException) on the formalisms that consume psf.kernel.native at image resolution and are deferred per the design: linear-function objects without an operated override, the data_linear_func_matrix preload, and InversionImagingSparse.psf_weighted_data.
  • MockPSF gains convolve_over_sample_size = 1 to match the real interface.

Test Plan

  • mapping_matrix_over_sampled delta-kernel identity: mean-binned rows == mapping_matrix to 1e-14.
  • End-to-end s=2: operated_mapping_matrix_list matches an independent brute-force fine-raster convolution + bin (plain loops, no shared indexing) to 1e-12.
  • Guard tests: linear-func objects and the kernel-native preload raise under an oversampled PSF.
  • Full suites against this branch: PyAutoArray / PyAutoGalaxy / PyAutoLens (counts in the issue sign-off).

Memory profile (design §4 risk)

Native FFT cube (ny·s, nx·s, n_src), fp64, for a realistic strong-lens case (fft frame 256² at s=1):

s frame 500 src 1000 src 2000 src
1 256² 0.26 GB 0.52 GB 1.05 GB
2 512² 1.05 GB 2.10 GB 4.19 GB
3 768² 2.36 GB 4.72 GB 9.44 GB

s=2 with ~1000 sources is ~2.1 GB (×4 the s=1 cube) plus FFT transients — fine on A100-class GPUs, tight on small (6 GB) cards. Oversampled inversion stays opt-in (nothing defaults on); chunked per-column convolution and/or use_mixed_precision are the mitigations if profiling shows pressure in practice.

Validation checklist (--auto run)

🤖 Generated with Claude Code

Implements phase 2b of the approved design (PyAutoMind
feature/autoarray/oversampling_design.md §4, approved in #353):

- Mapper.mapping_matrix_over_sampled: sub-resolution mapping matrix (one
  row per sub-pixel, per-pixel sub-block order, no sub_fraction fold) —
  built by the existing mapper_util.mapping_matrix_from with identity
  parent indices and unit fractions.
- AbstractInversionImaging._mapping_matrix_for_convolution_from routes all
  three PSF-convolution sites through the sub-resolution matrix for Mapper
  objects when psf.convolve_over_sample_size > 1; mapping.py needs no
  change (the PSF application site is the shared parent, as the design
  recorded).
- Loud InversionException guards on the image-resolution kernel-native
  formalisms deferred by the design: linear-func objects without an
  operated override, the data_linear_func_matrix preload, and
  InversionImagingSparse.psf_weighted_data.
- MockPSF models the new convolve_over_sample_size attribute.
- Tests: delta-kernel identity (1e-14), end-to-end s=2 vs an independent
  brute-force fine-raster convolution (1e-12), guard raises.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Jul 8, 2026
@Jammy2211
Jammy2211 merged commit ea75b94 into main Jul 8, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/psf-oversample-inversion branch August 25, 2026 18:16
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant